package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaishengit.entity.User;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class UserDao {

	private DBHelp<User> db = new DBHelp<User>();
	public User findByUserNameAndPassword(String username,String password) {
		String sql = "Select id,username,password from t_user where username = ? and password = ?";
		return db.executeSQLForObject(sql, new UserRowMapper(), username,password);
	} 
	private class UserRowMapper implements RowMapper<User>{

		public User mapperRow(ResultSet rs) throws SQLException {
			User user = new User();
			user.setId(rs.getInt("id"));
			user.setUsername(rs.getString("username"));
			user.setPassword(rs.getString("password"));
			return user;
		}
		
	}
}
